using UnityEngine;
using UnityEngine.UI;
/// <summary>移动摇杆控制类</summary>
public class MobileJoy : MonoBehaviour
{
    public Joystick joystick;//虚拟摇杆组件
    public RoleInfo role; // 角色组件
    public ButtonDownUp btnFire; // 开火按钮组件
    public Button btnOn;
    public Button[] btnGuns; // 切换武器按钮
    void Start()
    {
        btnFire.onPointerDown += () => role.SetFire(true); //按下开火
        btnFire.onPointerUp += () => role.SetFire(false); //松开停止
        btnOn.onClick.AddListener(() => role.OnEvent()); // 开启
        // 为每个枪械按钮添加点击事件监听器，点击时切换对应的武器
        for (int i = 0; i < btnGuns.Length; i++)
        {
            int id = i;
            btnGuns[id].onClick.AddListener(() => role.setGun(id));
        }
    }
    void Update()
    {
        if (joystick != null)
        { //防止摇杆没拖入
            role.Move(joystick.Horizontal, joystick.Vertical);//移动角色
        }
    }
}